from fastapi import APIRouter, Request
from finance.python.services import home_service
from finance.python.middleware.auth import token_required
from finance.python.middleware.logging import log_required

# 创建路由器
home_router = APIRouter(
    prefix="/api",
    tags=["home"]
)

@home_router.get("/get_statistics", summary="获取收支统计")
@token_required
@log_required
async def get_statistics(request: Request):
    """
    获取用户当月收支统计
    :param request: 请求对象
    :return: 收支统计数据
    """
    user_id = request.state.user_id
    return await home_service.get_statistics(user_id)

@home_router.get("/get_chart_data", summary="获取图表数据")
@token_required
@log_required
async def get_chart_data(request: Request):
    """
    获取最近6个月的收支趋势数据
    :param request: 请求对象
    :return: 图表数据
    """
    user_id = request.state.user_id
    return await home_service.get_chart_data(user_id)
